package com.me.libgdx_test;

import com.badlogic.gdx.Gdx;

/** A simple helper class to log the frames per seconds achieved. Just invoke the {@link #log()} method in your rendering method.
 * The output will be logged once per second.
 * 
 * @author mzechner */
public class ClassCustomFPSLogger {
	long startTime;
	long click;
	long latency;
	long render;

	public ClassCustomFPSLogger () {
		startTime = System.currentTimeMillis();
		click=0;
		latency = 0;
		render = 0;
	}

	/** Logs the current frames per second to the console. */
	public void log () {
		if (System.currentTimeMillis() - startTime > 1000) {
			Gdx.app.log("FPSLogger", "fps: " + Gdx.graphics.getFramesPerSecond());
			startTime = System.currentTimeMillis();
		}
	}
	
	public void click(){
		click = System.currentTimeMillis();
		latency = 0;
		render = 0;
	}
	
	public String getFPS(){
		//ClassLogDisplay.print("FPS: " + String.valueOf(Gdx.graphics.getFramesPerSecond()));
		return "FPS: " + String.valueOf(Gdx.graphics.getFramesPerSecond());
	}
	
	public void setClickLatency(){
		if (latency==0)
			{latency = System.currentTimeMillis();}
	}
	
	public String getClickLatency(){
		//ClassLogDisplay.print("ClickLat: " + String.valueOf((latency-click)));
		return "ClickLat: " + String.valueOf((latency-click));
	}
	
	public String getClickRenderLatency(){
		if(render==0){
			render = System.currentTimeMillis();
		}
		//ClassLogDisplay.print("ClickRenderLat: " + String.valueOf((render-click)));
		return "ClickRenderLat: " + String.valueOf((render-click));
	}
}